//转出
function transferout(row, index) {
	closeWindow('confirmModal');
	var item = row.parentElement.children[index];
	var options = {
		"accountNumber" : localStorage.accountNum,
		"token" : localStorage.token,
		"serialNumber" : item.cells[0].innerText
	};
	var para = JSON.stringify(options);
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/transferreview",
		data : para,
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			var data = result.data;
			if (data.status) {
				// 查询到的数据
				alert(data.promptMessage);
				queryHistory();
			} else {
				alert(data.promptMessage);
			}
		}
	});
}

var historyOrder = [];
var currentPage = 1;
var totalPage = 1;
// 转出审核列表
function queryHistory() {
	var options = {
		"accountNumber" : localStorage.accountNum,
		"token" : localStorage.token
	};
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/tranout",
		data : JSON.stringify(options),
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			if (result.message == "SUCCESS") {
				// data为请求到的数据
				var data = result.data;
				historyOrder = data;
				totalPage = Math.ceil(data.length / 10);
				if (totalPage === 0) {
					var noData = "<div style='width:100%;height:30px;margin:40px 0;text-align: center;'>暂无表格数据</div>"
					document.getElementById("transferNoData").innerHTML = noData;
				}
				document.getElementById("transferTotal").innerText = "";
				$("#transferTotal").append(totalPage);
				dealData();
			} else {
				alert("数据请求错误！");
			}
		}
	});
	
}
//确认转出弹窗
function confirmWin(index) {
	confirmIndex = index;
	openWindow('confirmModal');
}

// 处理交易记录表格数据展示
function dealData() {
	var displayOrder = [];
	$("#displayData").find("tr").remove();
	if (totalPage < 1 || currentPage === totalPage) {
		$("#nextPageBtn").attr("disabled", true);
	} else {
		$("#nextPageBtn").attr("disabled", false);
	}
	if (currentPage === 1) {
		$("#prePageBtn").attr("disabled", true);
	} else {
		$("#prePageBtn").attr("disabled", false);
	}
	document.getElementById("currentPage").innerText = currentPage;
	var j = 0;
	for (var i = (currentPage - 1) * 10; i < currentPage * 10; i++) {
		var item = historyOrder[i];
		if (!item) {
			return;
		}
		item.index = j;
		displayOrder.push(item);
		row = document.createElement("tr"); // 创建行
		td1 = document.createElement("td"); // 流水号
		td2 = document.createElement("td"); // 用户账号
		td3 = document.createElement("td"); // 交易类型
		td4 = document.createElement("td"); // 收款人
		td5 = document.createElement("td"); // 银行卡号
		td6 = document.createElement("td"); // 银行名称
		td7 = document.createElement("td"); // 金额
		td8 = document.createElement("td"); // 用户手机号
		td9 = document.createElement("td"); // 订单状态
		td10 = document.createElement("td"); // 操作时间
		td11 = document.createElement("td"); // 提交时间
		td1.appendChild(document.createTextNode(item.serialNumber)); // 为单元格添加内容 
		td2.appendChild(document.createTextNode(item.customerCode));
		td3.appendChild(document.createTextNode(item.transactionType));
		td4.appendChild(document.createTextNode(item.userName));
		td5.appendChild(document.createTextNode(item.bankNumber));
		td6.appendChild(document.createTextNode(item.bankName));
		td7.appendChild(document.createTextNode(item.amount));
		td8.appendChild(document.createTextNode(item.phone));
		td9.appendChild(document.createTextNode(item.statusInformation));
		td10.appendChild(document.createTextNode(item.operatingTime));
		if(item.statusInformation === "处理中"){
			td11.innerHTML = "<a class='commonLink' style='color:#00f' onclick='confirmWin("
				+ item.index + ")'>未确认</a>";
		}else{
			td11.innerHTML = "<span style='color:#999'>已确认</span>";
		}		
		row.appendChild(td1);
		row.appendChild(td2);
		row.appendChild(td3);
		row.appendChild(td4);
		row.appendChild(td5);
		row.appendChild(td6);
		row.appendChild(td7);
		row.appendChild(td8);
		row.appendChild(td9);
		row.appendChild(td10);
		row.appendChild(td11);
		$("#displayData").append(row);
		j++;
	}
}
// 上一页
function prePage() {
	currentPage--;
	dealData();
}
// 下一页
function nextPage() {
	currentPage++;
	dealData();
}